package com.lch.webdemo.wxhandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;

/**
 * 扫码事件
 *
 * @author liuchenhui
 */
@Component
public class ScanHandler extends AbstractHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(MenuHandler.class);

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService wxMpService,
                                    WxSessionManager sessionManager) {

//        WxMpKefuService kfService = new WxMpKefuServiceImpl(wxMpService);
//        WeixinService weixinService = (WeixinService) wxMpService;
//        try {
//            String key = wxMessage.getEventKey();
//            String openId = wxMessage.getFromUser();
//            WxMpUser userWxInfo = weixinService.getUserService().userInfo(openId, null);
//
//            if (StringUtil.isNotBlank(key) && key.startsWith(QRCODE_PRE)) {
//                String[] strArr = key.split("\\|");
//                String sceneId = strArr.length >= 2 ? strArr[1] : "";
//                ScanEventKeyEnum scanEvent = ScanEventKeyEnum.findScanEventByKey(sceneId);
//                // 处理事件
//                handle(scanEvent, userWxInfo, kfService);
//            }
//        } catch (WxErrorException e) {
//            LOGGER.error("菜单事件处理失败", e);
//        }
        return null;
    }
//
//    // 消息回复
//    private void handle(ScanEventKeyEnum scanEvent, WxMpUser userWxInfo, WxMpKefuService kfService) throws WxErrorException {
//        String replay;
//        switch (scanEvent){
//            case RSTJ_GAME_TEXT:
//                replay = String.format(scanEvent.getContent(), userWxInfo.getNickname(), customConfig.getRstjPageUrl());
//                break;
//            case SUBSCRIBE_BOOK_GAME_TEXT:
//                replay = SUBSCRIBE_BOOK_GAME_TEXT.getContent();
//                break;
//            default:
//                replay = SUBSCRIBE_REPLY.getMsgDesc();
//        }
//        WxMpKefuMessage textMessage = WxMpKefuMessage.TEXT().content(replay).toUser(userWxInfo.getOpenId()).build();
//        kfService.sendKefuMessage(textMessage);
//    }
}
